using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class YH_ScreeningPlanUserService : BaseAppService<YH_ScreeningPlanUserDto, YH_ScreeningPlanUser, YH_ScreeningPlanUserRepository>
    {
        readonly ExcelHelp _excelHelp;
        public YH_ScreeningPlanUserService(YH_ScreeningPlanUserRepository repository, ExcelHelp excelHelp) : base(repository)
        {
            _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<YH_ScreeningPlanUser, YH_ScreeningPlanUserDto>
            GetLoadPageOffsetMode(PagingModel<YH_ScreeningPlanUserDto>
                pagingQueryModel)
        {
            var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
            var baseQuery = _repository.QueryBase().AsNoTracking();
            loadPageOffsetModel.QueryWhere = this.CreateQRList()

     .Add("ScreeningPlanId", "=") //
     .Add("UserId", "=");//


            loadPageOffsetModel.BasqQuery = baseQuery;
            loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
            loadPageOffsetModel.Selector = model => new YH_ScreeningPlanUser()
            {
                Id = model.Id,
                ScreeningPlanId = model.ScreeningPlanId,//
                UserId = model.UserId,//
            };
            return loadPageOffsetModel;
        }


        public async Task<IPageModel<YH_ScreeningPlanUserDto>> GetList(PagingModel<YH_ScreeningPlanUserDto>
            pagingQueryModel)
        {
            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
            return await base.LoadPageOffsetAsync(loadPageOffsetModel);
        }


        public async Task<string>
            Export(PagingModel<YH_ScreeningPlanUserDto>
                pagingQueryModel)
        {
            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
            var excelData = DataList.Select(model => new
            {
                model.ScreeningPlanId,
                ScreeningPlanId_title = "",
                model.UserId,
                UserId_title = "",
            }).ToList();




            return _excelHelp.Create(excelData);
        }

    }

}
